﻿using BCCommon;
using BCDto.TMS.NightFreightConfiguration;
using BCService.TMS.NightFreightConfiguration;
using BCTMSRESTful.Configs;
using BCTMSRESTful.Controllers.Management;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace BCTMSRESTful.Controllers.Management.TMS.NightFreightConfiguration
{
    /// <summary>
    /// 夜间运费配置
    /// </summary>
    [Route("api/v1/sim/[controller]")]
    [ApiExplorerSettings(GroupName = "TMSAdmin")]
    public class NightFreightConfigurationController : ManagementBaseController
    {
        private readonly INightFreightConfigurationService nightFreightConfigurationService;

        public NightFreightConfigurationController(INightFreightConfigurationService nightFreightConfigurationService)
        {
            this.nightFreightConfigurationService = nightFreightConfigurationService;
        }

        /// <summary>
        /// 创建夜间运费配置
        /// </summary>
        /// <param name="requestDto">夜间运费配置信息</param>
        /// <response code="201">创建夜间运费配置</response>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(NightFreightConfigurationViewDto), 201)]
        [Log("创建夜间运费配置")]
        public IActionResult Post([FromBody] NightFreightConfigurationRequestDto requestDto)
        {
            var result = this.nightFreightConfigurationService.Create(this.Admin, requestDto);
            return this.Ok(result);
        }

        /// <summary>
        /// 获取夜间运费配置
        /// </summary>
        /// <param name="orderExtractProportion">订单抽取比例(百分比)</param>
        /// <param name="startHour">开始小时</param>
        /// <param name="startMinute">开始分钟</param>
        /// <param name="endHour">结束小时</param>
        /// <param name="endMinute">结束分钟</param>
        /// <param name="pageIndex">页号</param>
        /// <param name="pageSize">每页数据条数</param>
        /// <response code="200">获取夜间运费配置</response>
        /// <returns></returns>
        [HttpGet]
        [ProducesResponseType(typeof(PageableList<NightFreightConfigurationViewDto>), 200)]
        public IActionResult Query([FromQuery(Name = "order_extract_proportion")] int? orderExtractProportion,
            [FromQuery(Name = "start_hour")]int? startHour,
            [FromQuery(Name = "start_minute")]int? startMinute,
            [FromQuery(Name = "end_hour")]int? endHour,
            [FromQuery(Name = "end_minute")]int? endMinute,
            [FromQuery(Name = "page_index")]int pageIndex = 1,
            [FromQuery(Name = "page_size")]int pageSize = 10)
        {
            var result = this.nightFreightConfigurationService.Query(this.Admin, orderExtractProportion, startHour, startMinute, endHour, endMinute, pageIndex, pageSize);
            return this.Ok(result);
        }

        /// <summary>
        /// 修改夜间运费配置
        /// </summary>
        /// <param name="putDto">夜间运费配置修改信息</param>
        /// <response code="200">创建夜间运费配置</response>
        /// <returns></returns>
        [HttpPut]
        [ProducesResponseType(typeof(NightFreightConfigurationViewDto), 200)]
        [Log("修改夜间运费配置")]
        public IActionResult Put([FromBody] NightFreightConfigurationPutDto putDto)
        {
            var result = this.nightFreightConfigurationService.Update(this.Admin, putDto);
            return this.Ok(result);
        }

        /// <summary>
        /// 删除总部夜间运费配置
        /// </summary>
        /// <param name="nightFreightConfigurationId">夜间运费配置Id</param>
        /// <response code="204">删除总部夜间运费配置</response>
        /// <returns></returns>
        [HttpDelete("{night_freight_configuration_id}")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        [Log("删除总部夜间运费配置")]
        public IActionResult Delete([FromRoute(Name = "")]long nightFreightConfigurationId)
        {
            this.nightFreightConfigurationService.Delete(this.Admin, nightFreightConfigurationId);
            return NoContent();
        }

        /// <summary>
        /// 删除代理商夜间运费配置
        /// </summary>
        /// <param name="agentNightFreightConfigurationId">代理商夜间运费配置Id</param>
        /// <response code="204">删除代理商夜间运费配置</response>
        /// <returns></returns>
        [HttpDelete("[action]/{agent_night_freight_configuration_id}")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        [Log("删除代理商夜间运费配置")]
        public IActionResult DeleteAgent([FromRoute(Name = "agent_night_freight_configuration_id")]long agentNightFreightConfigurationId)
        {
            this.nightFreightConfigurationService.DeleteAgent(this.Admin, agentNightFreightConfigurationId);
            return NoContent();
        }

        /// <summary>
        /// 获取夜间运费配置
        /// </summary>
        /// <param name="orderExtractProportion">订单抽取比例(百分比)</param>
        /// <param name="startHour">开始小时</param>
        /// <param name="startMinute">开始分钟</param>
        /// <param name="endHour">结束小时</param>
        /// <param name="endMinute">结束分钟</param>
        /// <response code="200">获取夜间运费配置</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(IEnumerable<NightFreightConfigurationViewDto>), 200)]
        public IActionResult List([FromQuery(Name = "order_extract_proportion")] int? orderExtractProportion,
            [FromQuery(Name = "start_hour")] int? startHour,
            [FromQuery(Name = "start_minute")] int? startMinute,
            [FromQuery(Name = "end_hour")] int? endHour,
            [FromQuery(Name = "end_minute")] int? endMinute)
        {
            var result = this.nightFreightConfigurationService.GetList(this.Admin, orderExtractProportion, startHour, startMinute, endHour, endMinute);
            return this.Ok(result);
        }
    }
}
